package com.lhy.controller;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.lhy.domain.NewMessage;
import com.lhy.domain.Result;
import com.lhy.service.IUserService;

@Controller
@RequestMapping("/updatemessage")
public class UpdateMessageController {
	@Autowired
	private IUserService userService;
	
	@RequestMapping("/do")
	public @ResponseBody
	Map<String, Object> add(String author, String title, String content, String newMessage_id)  {
		Map<String, Object> returnMap = new HashMap<>();
		Result result=new Result();
		result.setCode("1");
		result.setDes("成功");
		Date date = new Date();       
		Timestamp create_dt = new Timestamp(date.getTime());
		try{
			userService.updateNewMessage(author,title,content,create_dt,Integer.valueOf(newMessage_id));
		}catch(Exception e){
			e.printStackTrace();
			result.setCode("0");
			result.setDes(e.getMessage());
		}
		returnMap.put("result", result);
		return returnMap;
	}
	@RequestMapping("/update")
	public @ResponseBody
	Map<String, Object> update(String newmessage_id)  {
		Map<String, Object> returnMap = new HashMap<>();
		Result result=new Result();
		result.setCode("1");
		result.setDes("成功");     
		try{
			NewMessage newmessage = userService.queryNewMessageById(Integer.valueOf(newmessage_id));
			returnMap.put("newmessage", newmessage);
			
		}catch(Exception e){
			e.printStackTrace();
			result.setCode("0");
			result.setDes(e.getMessage());
		}
		
		returnMap.put("result", result);
		return returnMap;
	}
	@RequestMapping("/delete")
	public @ResponseBody
	Map<String, Object> delete(String newmessage_id)  {
		Map<String, Object> returnMap = new HashMap<>();
		Result result=new Result();
		result.setCode("1");
		result.setDes("成功");     
		try{
			NewMessage newmessage = userService.queryNewMessageById(Integer.valueOf(newmessage_id));
			returnMap.put("newmessage", newmessage);
			
		}catch(Exception e){
			e.printStackTrace();
			result.setCode("0");
			result.setDes(e.getMessage());
		}
		
		returnMap.put("result", result);
		return returnMap;
	}
}
